********************************************************************************
** 	TITLE:		at2013_autnes_contact_networks                                ** 	
**	AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       ZA5859_en_v2-0-1                                              **
**	DATE:		October 2022 					                              **	
**	VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "at2013_autnes_contact_networks", replace

* Open the dataset

use "ZA5859_en_v2-0-1.dta", clear


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen surveydate = date

format %tdMon_DD,_CCYY surveydate

gen edate = 20130929

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = (electiondate - surveydate) + 1 // Add 1 to correct for election date

* Gender

gen male = zpsex

recode male (2=0)

* Age

gen age = zpage

replace age = . if age < 15

* Education

gen education = w1_q88

recode education (5=.)
recode education (15=.)
recode education (99=.)

replace education = 1 if education == 1
replace education = 2 if education == 2
replace education = 3 if education == 3
replace education = 4 if education == 4
replace education = 5 if education == 6
replace education = 5 if education == 7
replace education = 6 if education == 8
replace education = 7 if education == 9
replace education = 8 if education == 10
replace education = 9 if education == 11
replace education = 10 if education == 12
replace education = 11 if education == 13
replace education = 12 if education == 14

* Interest for election

gen interest = w1_q4

recode interest (88=.)
recode interest (99=.)

replace interest = 5 - interest

* Party identification (national)

gen pidstatus_whole = .

replace pidstatus_whole = 9999 if w1_q43 == .
replace pidstatus_whole = 9999 if w1_q43 == 88
replace pidstatus_whole = 9999 if w1_q43 == 99

replace pidstatus_whole = 2 if w1_q41 == 2 & w1_q42 == 2 | w1_q41 == 1 & w1_q43 == 12 | w1_q42 == 1 & w1_q43 == 12

replace pidstatus_whole = 3 if w1_q43 == 1 & pidstatus_whole!=2 & pidstatus_whole!=9999
replace pidstatus_whole = 3 if w1_q43 == 2 & pidstatus_whole!=2 & pidstatus_whole!=9999

replace pidstatus_whole = 1 if w1_q43!=1 & w1_q43!=2 & pidstatus_whole!=2 & pidstatus_whole!=3 & pidstatus_whole!=9999

replace pidstatus_whole = . if pidstatus_whole == 9999

label define pidstatus 1 "Loser PID" 2 "No PID" 3 "Winner PID"
label values pidstatus_whole pidstatus

* Party identification scale (national)

gen pidscale_whole = .

replace pidscale_whole = 1 if pidstatus_whole == 1 & w1_q44 == 1
replace pidscale_whole = 2 if pidstatus_whole == 1 & w1_q44 == 2
replace pidscale_whole = 3 if pidstatus_whole == 1 & w1_q44 == 3
replace pidscale_whole = 4 if pidstatus_whole == 2
replace pidscale_whole = 5 if pidstatus_whole == 3 & w1_q44 == 3
replace pidscale_whole = 6 if pidstatus_whole == 3 & w1_q44 == 2
replace pidscale_whole = 7 if pidstatus_whole == 3 & w1_q44 == 1

label define pidscale 1 "Very strong loser PID" 2 "Fairly strong loser PID" 3 "Not very strong loser PID" 4 "No PID" 5 "Not very strong winner PID" 6 "Fairly strong winner PID" 7 "Very strong winner PID"
label values pidscale_whole pidscale

* TV news attentiveness

gen tv = 6 - w2_q33

recode tv (88=.)
recode tv (99=.)
recode tv (.=-99)

* Press news attentiveness

gen press = 6 - w2_q36

recode press (88=.)
recode press (99=.)
recode press (.=-99)

* Internet news attentiveness

gen internet = 6 - w2_q41

recode internet (88=.)
recode internet (99=.)
recode internet (.=-99)

* News attentiveness index

egen news = rowmax(tv press internet)

recode news (-99=.)

* Voting age for national parliamentary elections

gen votingage = w2_q50

replace votingage = 0 if votingage!=4
replace votingage = 1 if votingage == 4

* Percentage of votes a political party requires to enter the National Council

gen threshold5_1 = w2_q51

replace threshold5_1 = 0 if threshold5_1!=2 & threshold5_1!=5
replace threshold5_1 = 1 if threshold5_1 == 2 | threshold5_1 == 5

gen threshold5_2 = w2_q51b

replace threshold5_2 = 0 if threshold5_2!=1 & threshold5_2!=5
replace threshold5_2 = 1 if threshold5_2 == 1 | threshold5_2 == 5

gen threshold5 = max(threshold5_1,threshold5_2)

* Who appoints the Austrian Federal Chancellor

gen appoint = w2_q52

replace appoint = 0 if appoint!=1
replace appoint = 1 if appoint == 1

* Match Maria Fekter with party - Correct answer (OVP) = 1, Incorrect answer = 0

gen fekter = w2_q53x1

replace fekter = 0 if fekter!=2
replace fekter = 1 if fekter == 2

* Match Alois Stöger with party - Correct answer (SPO) = 1, Incorrect answer = 0

gen stoger = w2_q53x2

replace stoger = 0 if stoger!=1
replace stoger = 1 if stoger == 1

* Match Rudolf Hundstorfer with party - Correct answer (SPO) = 1, Incorrect answer = 0

gen hundstorfer = w2_q53x3

replace hundstorfer = 0 if hundstorfer!=1
replace hundstorfer = 1 if hundstorfer == 1

* Political knowledge index

gen knowledge = votingage + threshold5 + appoint + fekter + stoger + hundstorfer

* Political discussion

gen discussion_family = w1_q66x1
gen discussion_friends = w1_q66x2
gen discussion_colleagues = w1_q66x3
gen discussion_neighbors = w1_q66x4

recode discussion_family discussion_friends discussion_colleagues discussion_neighbors (88=.)
recode discussion_family discussion_friends discussion_colleagues discussion_neighbors (99=.)
recode discussion_family discussion_friends discussion_colleagues discussion_neighbors (77=4)

replace discussion_family = 4 - discussion_family
replace discussion_friends = 4 - discussion_friends
replace discussion_colleagues = 4 - discussion_colleagues
replace discussion_neighbors = 4 - discussion_neighbors

gen discussion = discussion_family + discussion_friends + discussion_colleagues + discussion_neighbors

gen discussion_family_3pts = discussion_family
replace discussion_family_3pts = 0 if discussion_family == 1
replace discussion_family_3pts = 1 if discussion_family == 2
replace discussion_family_3pts = 2 if discussion_family == 3

gen discussion_friends_3pts = discussion_friends
replace discussion_friends_3pts = 0 if discussion_friends == 1
replace discussion_friends_3pts = 1 if discussion_friends == 2
replace discussion_friends_3pts = 2 if discussion_friends == 3

gen discussion_colleagues_3pts = discussion_colleagues
replace discussion_colleagues_3pts = 0 if discussion_colleagues == 1
replace discussion_colleagues_3pts = 1 if discussion_colleagues == 2
replace discussion_colleagues_3pts = 2 if discussion_colleagues == 3

gen discussion_neighbors_3pts = discussion_neighbors
replace discussion_neighbors_3pts = 0 if discussion_neighbors == 1
replace discussion_neighbors_3pts = 1 if discussion_neighbors == 2
replace discussion_neighbors_3pts = 2 if discussion_neighbors == 3

egen discussion_3pts = rowmax(discussion_family_3pts discussion_friends_3pts discussion_colleagues_3pts discussion_neighbors_3pts)

* Coalition preference

gen coalpref1 = max(w1_q58x1,w1_q61x1)
gen coalpref2 = max(w1_q58x2,w1_q61x2)
gen coalpref3 = max(w1_q58x3,w1_q61x3)
gen coalpref4 = max(w1_q58x4,w1_q61x4)

recode coalpref1 coalpref2 coalpref3 coalpref4 (88=.)
recode coalpref1 coalpref2 coalpref3 coalpref4 (99=.)

gen complete_coalpref = 1 if coalpref1!=. & coalpref2!=. & coalpref3!=. & coalpref4!=.

gen coalpref = 3 if coalpref2 >= coalpref1 & coalpref2 >= coalpref3 & coalpref2 >= coalpref4 & complete_coalpref == 1
replace coalpref = 2 if coalpref1 == coalpref2 & coalpref1 == coalpref3 & coalpref1 == coalpref4 & complete_coalpref == 1
replace coalpref = 1 if coalpref!=2 & coalpref!=3 & complete_coalpref == 1

replace coalpref = . if coalpref == 3 & coalpref2 == coalpref1 & complete_coalpref == 1
replace coalpref = . if coalpref == 3 & coalpref2 == coalpref3 & complete_coalpref == 1
replace coalpref = . if coalpref == 3 & coalpref2 == coalpref4 & complete_coalpref == 1

label define coalpref 1 "Loser coalition" 2 "No preference" 3 "Winner coalition"
label values coalpref coalpref

* Coalition preference strength

gen coalstrength1 = coalpref1 if coalpref1 >= coalpref2 & coalpref1 >= coalpref3 & coalpref1 >= coalpref4 & complete_coalpref == 1
gen coalstrength2 = coalpref2 if coalpref2 >= coalpref1 & coalpref2 >= coalpref3 & coalpref2 >= coalpref4 & complete_coalpref == 1
gen coalstrength3 = coalpref3 if coalpref3 >= coalpref1 & coalpref3 >= coalpref2 & coalpref3 >= coalpref4 & complete_coalpref == 1
gen coalstrength4 = coalpref4 if coalpref4 >= coalpref1 & coalpref4 >= coalpref2 & coalpref4 >= coalpref3 & complete_coalpref == 1

gen coalstrength = max(coalstrength1,coalstrength2,coalstrength3,coalstrength4)

replace coalstrength = 300 if coalstrength == 7 | coalstrength == 8 | coalstrength == 9 | coalstrength == 10
replace coalstrength = 200 if coalstrength == 4 | coalstrength == 5 | coalstrength == 6
replace coalstrength = 100 if coalstrength == 0 | coalstrength == 1 | coalstrength == 2 | coalstrength == 3

replace coalstrength = 3 if coalstrength == 300
replace coalstrength = 2 if coalstrength == 200
replace coalstrength = 1 if coalstrength == 100

label define coalstrength 1 "Weak preference" 2 "Moderate preference" 3 "Strong preference"
label values coalstrength coalstrength

* Coalition preference scale

gen coalscale = .

replace coalscale = 1 if coalpref == 1 & coalstrength == 3
replace coalscale = 2 if coalpref == 1 & coalstrength == 2
replace coalscale = 3 if coalpref == 1 & coalstrength == 1
replace coalscale = 4 if coalpref == 2
replace coalscale = 5 if coalpref == 3 & coalstrength == 1
replace coalscale = 6 if coalpref == 3 & coalstrength == 2
replace coalscale = 7 if coalpref == 3 & coalstrength == 3

label define coalscale 1 "Strong loser preference" 2 "Moderate loser preference" 3 "Weak loser preference" 4 "No preference" 5 "Weak winner preference" 6 "Moderate winner preference" 7 "Strong winner preference" 
label values coalscale coalscale


*********************************
** NATIONAL-LEVEL EXPECTATIONS ** 
*********************************

* Generate variable identifying incomplete answers

gen winCoalition1 = max(w1_q59x1,w1_q62x1)
gen winCoalition2 = max(w1_q59x2,w1_q62x2)
gen winCoalition3 = max(w1_q59x3,w1_q62x3)
gen winCoalition4 = max(w1_q59x4,w1_q62x4)

recode winCoalition1 winCoalition2 winCoalition3 winCoalition4 (88=.)
recode winCoalition1 winCoalition2 winCoalition3 winCoalition4 (99=.)

replace winCoalition1 = 5 - winCoalition1
replace winCoalition2 = 5 - winCoalition2
replace winCoalition3 = 5 - winCoalition3
replace winCoalition4 = 5 - winCoalition4

gen complete_whole = 1 if winCoalition1!=. & winCoalition2!=. & winCoalition3!=. & winCoalition4!=.

* Generate value of 1 if the expectation for one coalition is higher or equal to the expectations for at least one other coalition

gen coalition1 = 1 if winCoalition1 >= winCoalition2 & winCoalition1 >= winCoalition3 & winCoalition1 >= winCoalition4 & complete_whole == 1

gen coalition2 = 1 if winCoalition2 >= winCoalition1 & winCoalition2 >= winCoalition3 & winCoalition2 >= winCoalition4 & complete_whole == 1

gen coalition3 = 1 if winCoalition3 >= winCoalition1 & winCoalition3 >= winCoalition2 & winCoalition3 >= winCoalition4 & complete_whole == 1

gen coalition4 = 1 if winCoalition4 >= winCoalition1 & winCoalition4 >= winCoalition2 & winCoalition4 >= winCoalition3 & complete_whole == 1

gen coalitionOTH = 1 if winCoalition1 == 1 & winCoalition2 == 1 & winCoalition3 == 1 & winCoalition4 == 1 & complete_whole == 1

replace coalition1 = . if coalitionOTH == 1 & complete_whole == 1
replace coalition2 = . if coalitionOTH == 1 & complete_whole == 1
replace coalition3 = . if coalitionOTH == 1 & complete_whole == 1
replace coalition4 = . if coalitionOTH == 1 & complete_whole == 1

* Generate variable for ambiguous forecasts

gen ambiguous_whole = .

replace ambiguous_whole = 99 if coalition1 == coalition2 & coalition1!=. | coalition1 == coalition3 & coalition1!=. | coalition1 == coalition4 & coalition1!=.

replace ambiguous_whole = 99 if coalition2 == coalition1 & coalition2!=. | coalition2 == coalition3 & coalition2!=. | coalition2 == coalition4 & coalition2!=.

replace ambiguous_whole = 99 if coalition3 == coalition1 & coalition3!=. | coalition3 == coalition2 & coalition3!=. | coalition3 == coalition4 & coalition3!=.

replace ambiguous_whole = 99 if coalition4 == coalition1 & coalition4!=. | coalition4 == coalition2 & coalition4!=. | coalition4 == coalition3 & coalition4!=.

* Generate value of 0 for lower expectations

replace coalition1 = 0 if coalition1!=1 & coalition1!=. & complete_whole == 1
replace coalition2 = 0 if coalition2!=1 & coalition2!=. & complete_whole == 1
replace coalition3 = 0 if coalition3!=1 & coalition3!=. & complete_whole == 1
replace coalition4 = 0 if coalition4!=1 & coalition4!=. & complete_whole == 1
replace coalitionOTH = 0 if coalitionOTH!=1 & coalitionOTH!=. & complete_whole == 1

* Forecasts (1 = SPO-Greens, 2 = SPO-OVP, 3 = OVP-FPO, 4 = SPO-FPO, 88 = other, 99 = ambiguous)

gen forecast_whole = .

replace forecast_whole = 1 if coalition1 == 1 & complete_whole == 1
replace forecast_whole = 2 if coalition2 == 1 & complete_whole == 1
replace forecast_whole = 3 if coalition3 == 1 & complete_whole == 1
replace forecast_whole = 4 if coalition4 == 1 & complete_whole == 1
replace forecast_whole = 88 if coalitionOTH == 1 & complete_whole == 1
replace forecast_whole = 99 if ambiguous_whole == 1 & complete_whole == 1

* Identify correct and ambiguous forecasts

gen correct_whole = 0 if forecast_whole!=2 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 1 if forecast_whole == 2 & forecast_whole!=99 & forecast_whole!=. & complete_whole == 1

replace correct_whole = 0 if w1_q59x1 == 88 & w1_q59x2 == 88 & w1_q59x3 == 88 & w1_q59x4 == 88 | w1_q62x1 == 88 & w1_q62x2 == 88 & w1_q62x3 == 88 & w1_q62x4 == 88

replace correct_whole = 99 if forecast_whole == 99 & coalition2 == 1 & complete_whole == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_whole_d = correct_whole

replace correct_whole_d = 0 if correct_whole_d == 99
replace correct_whole_d = 1 if correct_whole_d == 1


**********
** SAVE **
**********

save "at2013_autnes.dta", replace


*************************
** MAIN ANALYSES: FULL **
*************************

* Regression analysis and percentage of correct and incorrect forecasts

logistic correct_whole_d discussion coalscale interest news age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1


******************************
** SUMMARY STATISTICS: FULL **
******************************

label variable correct_whole_d "Coalition formed (DV)"
label variable discussion "Discussion"
label variable coalscale "Coalition preference"
label variable pidscale_whole "National PID"
label variable interest "Interest"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

estpost tabstat correct_whole_d discussion coalscale interest news knowledge age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "at2013_autnes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2013 Austrian legislative election (AUTNES), national level") replace

eststo clear

log close